﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace QuickLifeHall.ERP.Pages.SystemBase.User
{
    public partial class UserAdd : Utilities.PageBase
    {
        DAL.SystemBase.User repository = new DAL.SystemBase.User();

        public UserAdd()
        {
            this.PageAccessType = Core.Web.PageAccessType.Authorization;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(Facade.SystemBase.User));
        }

        #region 执行Action的操作

        /*
        protected override void _ExecuteAction()
        {
            //执行Action中的处理
            if (!this.IsPostBack && !string.IsNullOrEmpty(this.Action))
            {
                //执行页面中实际定义的操作
                object obj = null;
                try
                {
                    obj = ExecuteAction();
                }
                catch (Exception ex)
                {
                    obj = new Entity.EasyUI.Result("error", "在执行Action时发生错误：" + ex.Message);
                }

                //向客户端返回Json字符串
                Common.HttpUtilities.ResponseJsonString(this.Response, obj);
            }
        }

        protected object ExecuteAction()
        {
            switch (this.Action)
            {
                case "Add":
                    {
                        string data = Common.HttpUtilities.GetRequestParam<string>(this.Request, "Data");
                        Entity.SystemBase.User user = Core.Extensions.SerializeExtensions.DeserializeFromJson<Entity.SystemBase.User>(data);
                        var existsEntity = this.repository.GetByName(user.UserName);
                        if (existsEntity != null)
                        {
                            return new Entity.EasyUI.Result("error", "用户名已存在，添加失败！");
                        }
                        else
                        {
                            repository.Insert(user);
                            return new Entity.EasyUI.Result("success", "新增用户成功！");
                        }
                    }
                default:
                    {
                        return new Entity.EasyUI.Result("error", "未定义的操作：" + this.Action);
                    }
            }
        }
        */
        #endregion


    }
}